package com.mashibing.jvm.c3_jmm;

public class DisorderOhter02 {

    static int a = 0;
    static boolean flag = false;
    public static void main(String[] args) {

        long count = 0;
        while (true){
            count++;
            a = 0;
            flag = false;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    a = 1;
                    flag =true;
                }
            }).start();
            if(flag && a == 0){
                System.out.println("第 "+ count + " 次，指令重排序 flag = "+ flag + ", a = "+ a);
                break;
            }
        }
    }
}
